//
//  MainController.swift
//  myWeibo
//
//  Created by 章发晨 on 2017/3/5.
//  Copyright © 2017年 章发晨. All rights reserved.
//

import UIKit

class MainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //要在哪里执行,就定义在哪里,在这个控制器里面弹出控制器
        let composeButtonClickClosure = {
            print("加好按钮点击了")
        }
        
        
        
        //使用自定义Tabbar
        let tabbar = Tabbar()
        tabbar.composeButtonClickClosure = composeButtonClickClosure
//        self.tabBar
        self.setValue(tabbar, forKey: "tabBar")

        addChildViewController(HomeController(), title: "首页", imgNamed: "tabbar_home")
        addChildViewController(MessageController(), title: "消息", imgNamed: "tabbar_message_center")
        addChildViewController(DiscoverController(), title: "发现", imgNamed: "tabbar_discover")
        addChildViewController(ProfileController(), title: "我", imgNamed: "tabbar_profile")
    }


    
    //添加子控制器,图片,名字
    func addChildViewController(vc: UIViewController, title: String, imgNamed: String) {
        //设置标题
        vc.title = title
        
        //设置图片
        vc.tabBarItem.image = UIImage(named: imgNamed)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        //设置文字属性
        //设置文字大小的时候只能设置Normal状态,只需要设置Normal状态
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(14)], forState: .Normal)
        
        
        
        
        //用导航控制器包装
        addChildViewController(UINavigationController(rootViewController: vc))
        
        
        
        
    }
    
    
    
    

}
